<template>
  <div class="home-box">
    <el-container style="height: 100%">
      <el-header>
        <span class="title">企业办公自动化系统</span>
        <span class="adminPic">
          <el-menu class="el-menu-demo" mode="horizontal" background-color="">
            <el-submenu index="2">
              <template slot="title">
                <span style="margin-right: 24px">
                  <el-badge :count="1">
                    <img :src="userPic" width="40" height="40" />
                  </el-badge>
                </span>
              </template>
              <el-menu-item index="2-1" @click="logout">
                &nbsp;<logout
                  theme="outline"
                  size="18"
                  fill="#4a4a4a"
                  class="logout-icon"
                />
                &nbsp;
                <span class="home-user">退出登录</span>
              </el-menu-item>
              <el-menu-item index="2-2" @click="goSelfCenter()">
                <i class="el-icon-user"></i>
                <span>个人中心</span>
              </el-menu-item>
              <el-menu-item index="2-3" @click="setting()">
                <i class="el-icon-s-tools"></i>
                <span>设置中心</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </span>
      </el-header>
      <el-container>
        <el-aside style="width: 200px; height: 100%">
          <el-menu
            default-active="1"
            unique-opened
            router
            class="el-menu-vertical-demo"
            background-color="rgb(40, 56, 72)"
            text-color="#fff"
            active-text-color="#ffd04b"
          >

        <input type="button" @click="goMyApply" value="123" />
        <input type="button" @click="goMyBank" value="testBank" />
        <input type="button" @click="goMyProSpence" value="testProSpence" />

            <el-submenu
              :index="item.menuId+''"
              v-for="item in menusForm"
              :key="item.menuId"
            >
              <template slot="title">
                <i class="item.menuPic"></i>
                <span>{{ item.menuName }}</span>
              </template>
              <el-menu-item
                :index="items.menuSrc"
                v-for="items in item.sonMenus"
                :key="items.menuId"
              >
                <template slot="title">
                  <i class="items.menuPic"></i>
                  <span>{{ items.menuName }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
      <!-- <el-footer>Footer</el-footer> -->
    </el-container>
  </div>
</template>

<script>
import { Logout, Dollar } from "@icon-park/vue";
export default {
  components: {
    Logout,
    Dollar,
  },
  data() {
    return {
      userAvatar: require("../assets/images/di.jpg"),
      userPic: "",
      baseUrl: "http://localhost:8080/brain",
      menusForm: [],
      currUser: {},
    };
  },
  created() {
    this.currUser = JSON.parse(sessionStorage.getItem("user"));
    this.userPic = "http://localhost:8080" + JSON.parse(this.currUser).userPic;
    this.getMenus();
  },
  methods: {
    //获取菜单
    getMenus() {
        let token=sessionStorage.getItem("token");
        console.log(token)
        this.$http.get("/menu/indexMenus",{headers: { token: sessionStorage.getItem("token") }}).then((res) => {  
          // console.log(res);
          if (res.code == 200) {
            this.menusForm = res.data;
          } else {
            this.$message.warning("获取菜单失败,请联系管理员!!!");
          }
        })
        .catch((err) => {
          this.$message.error("获取菜单失败,请联系管理员!!!");
        });
    },
    //退出
    logout() {
      this.$confirm("确定退出? 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          sessionStorage.clear();
          this.$router.push("/");
        })
        .catch(() => {});
    },
    goSelfCenter() {
      this.$router.push("/selfInfo");
    },
    //设置
    setting() {
      this.$router.push("/addMenu");
    },
    goMyApply() {
      this.$router.push("/showAllApply");

      this.$router.push("/showAllUser");
    },
    goMyBank() {
      this.$router.push("/bank");
    },
    goMyRole() {
      this.$router.push("/addRoleMenu");
    },
    goMyProSpence() {
      this.$router.push("/proSpence");
    },
  },
};
</script>

<style scoped>
.home-box {
  width: 100%;
  height: 100%;
}
.el-header {
  color: rgb(59, 84, 113);
  height: 60px;
  /* background-image: linear-gradient(160deg, #0093e9 0%, #80d0c7 100%); */
  display: flex;
  justify-content: space-between;
}
/* .el-footer {
  color: #333;
  text-align: center;
  line-height: 60px;
  background-image: linear-gradient(160deg, #0093e9 0%, #80d0c7 100%);
} */

.el-aside {
  background-color: rgb(40, 56, 72);
}

.el-main {
  /* height: 100%; */
  background-color: #e9eef3;
}
.home-box .title {
  width: 100%;
  height: 100%;
  font-size: 18px;
  line-height: 60px;
}
.home-box .home-user {
  margin-left: -10px;
}
.home-box .logout-icon {
  cursor: pointer;
}
.el-menu-item:hover {
  background-color: grey;
}
</style>
